<?php

namespace App\Http\ViewComposers;

use Illuminate\View\View;
use App\Http\Controllers\Home\Index\Api\IndexApi;
use App\Http\Controllers\Admin\Articles\Api\ArticlesApi;
use App\Http\Controllers\Admin\Categories\Api\CategoriesApi;
use App\Http\Controllers\Admin\Tags\Api\TagsApi;

class IndexComposer
{

    protected $articlesList;
    protected $categoriesList;
    protected $simpleCategories;
    protected $tagsList;
    protected $webInformation;

    public function __construct()
    {

        //获取分类列表
        $this->categoriesList = CategoriesApi::getCategoriesList('active');

        //处理分类,提取出ID作为键,名字作为值
        foreach($this->categoriesList as $cate) {
            $this->simpleCategories[$cate['id']] = $cate['name'];
        }

        //获取标签列表
        $this->tagsList = TagsApi::getTagsList();

        $this->webInformation = IndexApi::getInformation();

    }

    public function compose(View $view)
    {
        $view->with([

            'categoriesList' => $this->categoriesList,
            'simpleCategories' => $this->simpleCategories,
            'tagsList' => $this->tagsList,
            'webInformation' => $this->webInformation,

        ]);
    }

}
